"use client";

import { useEffect } from "react";
import dynamic from "next/dynamic";
import { getWechatOAuth2Url } from "@/constants/wechat";

// 使用客户端渲染组件以避免SSR警告
const WxpubPage = () => {
  useEffect(() => {
    if (sessionStorage.getItem('hasRedirected')) return;
    sessionStorage.setItem('hasRedirected', '1');
    const wechatOAuth2Url = getWechatOAuth2Url();
    window.location.href = wechatOAuth2Url;
  }, []);

  // 返回一个简单的加载提示，虽然通常不会被看到
  return (
    <div className="flex items-center justify-center min-h-screen bg-gray-100">
      <div className="text-center">
        <h1 className="text-xl font-semibold text-gray-800">正在跳转...</h1>
        <p className="mt-2 text-gray-600">请稍候，正在前往授权页面</p>
      </div>
    </div>
  );
};

// 导出为客户端组件，避免SSR
export default dynamic(() => Promise.resolve(WxpubPage), { ssr: false });
